﻿@using Blogifier.Core.Data
@inject IDataService DataService
@using Askmethat.Aspnet.JsonLocalizer.Localizer
@{
    ListModel listModel = (ListModel)Model;
    Pager pgr = listModel.Pager;
    string root = Url.Content("~/");
    string cover = $"{root}{listModel.Blog.Cover}";

    var posts = await DataService.BlogPosts.GetList(p => p.Published > DateTime.MinValue, new Pager(1));
    var flist = await DataService.BlogPosts.GetList(new Pager(1), 0, "", "F");
    var featured = flist.ToList();
    var popular = await DataService.BlogPosts.GetPopular(new Pager(1, 4));
}
@inject IJsonStringLocalizer<ListModel> Localizer
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" href="~/themes/vizew/img/core-img/favicon.ico">
    <link rel="stylesheet" href="~/themes/vizew/style.css">
    <partial name="~/Views/Shared/HeaderScript.cshtml" />
</head>

<body>
    <partial name="~/Views/Themes/Vizew/Shared/Header.cshtml" />
    <!-- ##### Vizew Post Area Start ##### -->
    <section class="vizew-post-area mb-50">
        <div class="container">
            <div class="row">
                <div class="col-12 col-md-7 col-lg-8">
                    <div class="all-posts-area">

                        <!-- Section Heading -->
                        <div class="section-heading style-2">
                            <h4>Latest Posts</h4>
                            <div class="line"></div>
                        </div>

                        @if (listModel.Posts.Count() > 0)
                        {
                            @foreach (var post in listModel.Posts)
                            {
                                <!-- Single Post Area -->
                                <div class="single-post-area mb-30">
                                    <div class="row align-items-center">
                                        <div class="col-12 col-lg-6">
                                            <!-- Post Thumbnail -->
                                            <div class="post-thumbnail">
                                                <img src="~/@post.Cover.ToThumb()" onerror="this.onerror=null;this.src='@root@post.Cover';" alt="@post.Title">
                                                <!-- Video Duration -->
                                                @if (post.Featured)
                                                {
                                                    <span class="video-duration"><i class="fa fa-star"></i>&nbsp;@Localizer["featured"]</span>
                                                }
                                            </div>
                                        </div>
                                        <div class="col-12 col-lg-6">
                                            <!-- Post Content -->
                                            <div class="post-content mt-0">

                                                @if (!string.IsNullOrEmpty(post.Categories))
                                                {
                                                    foreach (var cat in post.Categories.Split(',').ToList())
                                                    {
                                                        <a href="~/categories/@cat" class="post-cata cata-sm cata-danger">@cat</a>
                                                    }
                                                }
                                                <a href="posts/@post.Slug" class="post-title mb-2">@post.Title</a>
                                                <div class="post-meta d-flex align-items-center mb-2">
                                                    <span class="post-author">By @post.Author.DisplayName</span>
                                                    <i class="fa fa-circle" aria-hidden="true"></i>
                                                    <span class="post-date">@post.Published.ToFriendlyDateString()</span>
                                                </div>
                                                <p class="mb-2">@Html.Raw(post.Description)</p>
                                                <div class="post-meta d-flex">
                                                    <span><i class="fa fa-eye" aria-hidden="true"></i> @post.PostViews</span>
                                                    <span>
                                                        <i class="fa fa-comments-o" aria-hidden="true"></i>
                                                        <a href="posts/@post.Slug#disqus_thread"></a>
                                                    </span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            }
                            @if (pgr != null && (pgr.ShowOlder || pgr.ShowNewer))
                            {
                                <ul class="pagination justify-content-center">
                                    @if (pgr.ShowOlder)
                                    {
                                        <li class="item item-prev">
                                            <a class="post-cata cata-sm cata-danger" href="@pgr.LinkToOlder">
                                                <i class="item-icon fa fa-angle-left"></i>
                                            </a>
                                        </li>
                                    }
                                    <li><span class="pg-current">@pgr.CurrentPage</span></li>
                                    <li><span class="pg-last">out of @pgr.LastPage</span></li>
                                    @if (pgr.ShowNewer)
                                    {
                                        <li class="item item-next">
                                            <a class="post-cata cata-sm cata-danger" href="@pgr.LinkToNewer">
                                                <i class="item-icon fa fa-angle-right"></i>
                                            </a>
                                        </li>
                                    }
                                </ul>
                            }
                        }
                        else
                        {
                            <div class="notfound">@Localizer["empty"]</div>
                        }

                    </div>
                </div>

                <div class="col-12 col-md-5 col-lg-4">
                    <div class="sidebar-area">

                        <!-- ***** Sidebar Widget ***** -->
                        <div class="single-widget youtube-channel-widget mb-50">
                            <!-- Section Heading -->
                            <div class="section-heading style-2 mb-30">
                                <h4>@Localizer["featured"]</h4>
                                <div class="line"></div>
                            </div>

                            @if (featured.Any())
                            {
                                foreach (var item in featured)
                                {
                                    <div class="single-blog-post d-flex">
                                        <div class="post-thumbnail">
                                            <img src="~/@item.Cover.ToThumb()" onerror="this.onerror=null;this.src='@root@item.Cover';" alt="@item.Title">
                                        </div>
                                        <div class="post-content">
                                            <a href="~/posts/@item.Slug" class="post-title">@item.Title</a>
                                            <div class="post-meta d-flex">
                                                <span><i class="fa fa-eye" aria-hidden="true"></i> @item.PostViews</span>
                                                <span>
                                                    <i class="fa fa-comments-o" aria-hidden="true"></i>
                                                    <a href="posts/@item.Slug#disqus_thread"></a>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                }
                            }
                        </div>

                        <!-- ***** Single Widget ***** -->
                        <div class="single-widget mb-50">
                            <!-- Section Heading -->
                            <div class="section-heading style-2 mb-30">
                                <h4>@Localizer["popular"]</h4>
                                <div class="line"></div>
                            </div>

                            @if (popular.Any())
                            {
                                foreach (var pop in popular)
                                {
                                    <div class="single-blog-post d-flex">
                                        <div class="post-thumbnail">
                                            <img src="~/@pop.Cover.ToThumb()" onerror="this.onerror=null;this.src='@root@pop.Cover';" alt="@pop.Title">
                                        </div>
                                        <div class="post-content">
                                            <a href="~/posts/@pop.Slug" class="post-title">@pop.Title</a>
                                            <div class="post-meta d-flex">
                                                <span><i class="fa fa-eye" aria-hidden="true"></i> @pop.PostViews</span>
                                                <span>
                                                    <i class="fa fa-comments-o" aria-hidden="true"></i>
                                                    <a href="posts/@pop.Slug#disqus_thread"></a>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                }
                            }
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- ##### Vizew Psot Area End ##### -->
    <partial name="~/Views/Themes/Vizew/Shared/Footer.cshtml" />
</body>

</html>